<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>v-bind指令</title>
    <!--Vue中有两种数据绑定的方式： 
          1. v-bind 单向数据绑定:数据只能从data流向页面
          2. v-model 双向数据绑定：数据不仅能从data流向页面，还可以从页面流向data
            注：
                1.双向绑定一般用在表单类元素上，如input、select
                2.v-model:value可以简写为v-model，因为v-model默认收集的就是value值 -->
    <style>
      .active {
        border: 1px solid #000;
      }
      img {
        width: 50px;
        height: 50px;
        box-sizing: border-box;
      }
    </style>
  </head>
  <body>
    <div id="root">
      <img v-bind:src="imgSrc" alt="" />
      <br />
      <!-- v-bind简写 -->
      <img
        :src="imgSrc"
        alt=""
        :title="imgTitle+',你就知道！'"
        :class="isActive?'active':''"
        @click="toggleActive"
      />
      <br />
      <!-- 对象方式增删class -->
      <img
        :src="imgSrc"
        alt=""
        :title="imgTitle+',你就知道！'"
        :class="{active:isActive}"
        @click="toggleActive"
      />
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
      var vm = new Vue({
        el: "#root",
        data: {
          imgSrc:
            "//www.baidu.com/img/baidu_85beaf5496f291521eb75ba38eacbd87.svg",
          imgTitle: "百度一下",
          isActive: false,
        },
        methods: {
          toggleActive: function () {
            this.isActive = !this.isActive;
          },
        },
      });
    </script>
  </body>
</html>
